#ifndef KEY_H
#define KEY_H
#include "gd32f10x.h"
#include "general_config.h"

#define pressTimeout 5 //压力垫不上发数据超时5s
//默认值
#define def_lock 30000   //锁键时间 30s(最大32767)
#define def_hight 169   //默认身高
#define def_weight 70    //默认体重
#define def_wavelenth 10 //分钟
#define def_turnlenth 1 //分钟
//按键标志
#define WaitStatus 0//等待状态
#define PressStatus 1//按下状态
#define ReleaseStatus 2//释放状态
#define LongStatus 3//长按状态
#define KeyLongTime 80 //长按时间(KeyLongTime * KeyScanTime)
#define KeyScanTime 20 // ms
//键值
#define HeightKey 0x00000001
#define WeightKey 0x00000002
#define STATIC_ModeKey 0x00000004
#define NURSE_ModeKey 0x00000008
// #define TurnOverKey 0x00000008
#define WaveKey 0x00000010
#define UpKey 0x00000020
#define DownKey 0x00000040
#define LockKey 0x00000080
//参数最值
#define hight_max 250
#define hight_min 50
#define weight_max 200
#define weight_min 10
#define WaveLenth_max 60    //原版150
#define WaveLenth_min 1     // 5
#define TurnLenth_max 60    //翻身时间最大时间    150
#define TurnLenth_min 1    // 10  翻身最大时间   1

#define KeyKeepFre 100    //每KeyKeepFre ms加/减一次
#define WifiKeytTime 1500 //按键间隔最大时间2s

#define BeepKeytTime 1000 //按键间隔最大时间2s

#define KeyBackLed_ON() gpio_bit_set(GPIOB, GPIO_PIN_5);//PB5=1  （硬件取消了此功能）
#define KeyBackLed_OFF() gpio_bit_reset(GPIOB, GPIO_PIN_5);//PB5=0
typedef struct
{
    uint8_t KeyScanFre;
    uint8_t KeyRelease;
    uint8_t KeyStatus;
    uint8_t KeyPress;
    uint8_t KeyTimeReleaseCounts;
    uint8_t LongKeyFlag;
    uint8_t LongKeyRelease;
    uint8_t KeyValue;
    uint16_t KeyTimeCounts;
} Key_Struct_type;

extern Key_Struct_type Key_Struct;
// extern BYTE_t LimitStatus;
extern uint16_t key_option_time;

void limit_sw_init(void);
void SW_Process(void);
void Valve1Move(uint8_t posi);
void Valve2Move(uint8_t posi);
void key_init(void);
#endif
